package cn.coisini.api.admin;

import cn.coisini.model.common.dtos.Result;
import cn.coisini.model.common.enums.ResultEnum;
import cn.coisini.model.common.log.annotation.Log;
import cn.coisini.model.common.log.enums.BusinessType;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;
import java.util.List;

/**
 * @author xiangshaw
 * Description: 文件上传接口API
 */
@Tag(name = "文件上传接口API", description = "本地单文件上传、本地多文件上传、阿里云、Minio")
@RequestMapping("/api/v1/file")
public interface FileControllerApi {

    @Operation(summary = "本地单文件上传")
    @Log(title = "本地单文件上传", businessType = BusinessType.INSERT)
    @PostMapping("/admin/upload")
    Result<String> uploadFile(@RequestParam("file") MultipartFile file);

    @Operation(summary = "本地多文件上传")
    @Log(title = "本地多文件上传", businessType = BusinessType.INSERT)
    @PostMapping("/admin/uploads")
    Result<List<String>> uploadFiles(@RequestParam("files")MultipartFile[] files);

    @Operation(summary = "阿里云单文件上传")
    @Log(title = "阿里云单文件上传", businessType = BusinessType.INSERT)
    @PostMapping("/admin/ali/upload")
    Result<String> aliUploadFile(@RequestParam("file") MultipartFile file);

    @Operation(summary = "Minio文件上传")
    @Log(title = "Minio文件上传", businessType = BusinessType.INSERT)
    @PostMapping("/minio/upload")
    Result<List<String>> minioUploadFile(@RequestParam("files") MultipartFile[] files);

    @Operation(summary = "Minio文件预览")
    @Log(title = "Minio文件预览", businessType = BusinessType.SELECT)
    @GetMapping("/minio/preview/{fileName}")
    Result<String> minioPreviewFile(@PathVariable String fileName);

    @Operation(summary = "Minio文件下载")
    @Log(title = "Minio文件下载", businessType = BusinessType.EXPORT)
    @GetMapping("/minio/download/{fileName}")
    Result<InputStream> downloadFile(@PathVariable String fileName, HttpServletResponse response);

    @Operation(summary = "Minio文件删除")
    @Log(title = "Minio文件删除", businessType = BusinessType.DELETE)
    @DeleteMapping("/minio/delete/{fileName}")
    Result<ResultEnum> minioDeleteFile(@PathVariable String fileName);
}
